// @algorithm @lc id=100298 lang=cpp
// @title fan-zhuan-lian-biao-lcof

#include "algm/algm.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
    // @test([1,2,3,4,5])=[5,4,3,2,1]
public:
    ListNode *reverseList(ListNode *head) {
        if (head == nullptr) {
            return nullptr;
        }
        ListNode *cur = head, *succ = head->next, *prev = nullptr;
        while (cur != nullptr) {
            succ = cur->next;
            cur->next = prev;
            prev = cur;
            cur = succ;
        }
        return prev;
    }
};